$(function() {
	
	jQuery(document).ready(function () {
		if($("#isFollow").val()=="0"){
			$("#followBtn").html("轨迹跟踪");
		}else if($("#isFollow").val()=="1"){
			$("#followBtn").html("取消轨迹跟踪");
		}
		getUserInfo();
	});
	jQuery('#followBtn').on('click', function() {
		if($("#followBtn").html()=="轨迹跟踪"){
			$("#followBtn").html("取消轨迹跟踪");
			window.parent.window.setUserFollow($("#userId").val(),"1");
		}else{
			$("#followBtn").html("轨迹跟踪");
			window.parent.window.setUserFollow($("#userId").val(),"0");
		}
	});
	function getUserInfo(){
		var id = jQuery('#userId').val();
		 var url=window.rootPath+"/ui/index/getUserInfo/"+id;
         jQuery.ajax({
             url:encodeURI(url),
             cache:false,
             type : "get",
             dataType:"json",
             success:function(result){
            	 	var user = result.user;
            	 	jQuery("#name").val(user.name);
            	 	jQuery("#sex").val(user.sex);
            	 	jQuery("#contactType").val(user.contactType);
            	 	jQuery("#email").val(user.email);
            	 	jQuery("#position").val(user.position);
            	 	if(user.hierarchy){
            	 		jQuery("#hierarchy").val(user.hierarchy.groupName);
            	 	}
            	 	if(user.post){
            	 		jQuery("#post").val(user.post.title);
            	 	}
            	 		
            	 
				var avatarUrl=user.pictureAddress;
				if(avatarUrl==undefined||avatarUrl==""){
					avatarUrl=window.rootPath + "/img/nopicture.png";
				}else{
					avatarUrl=window.rootPath + '/'+avatarUrl;
				}
				jQuery("#iconAddress").prop("src", avatarUrl);
				
				
				var dealtWith = result.dealtWith;
				dealtWithHtml(dealtWith,$('#dealtWith'));

				var receive = result.receive;
				receiveHtml(receive,$('#receive'));
				
			}
         });
         
         function dealtWithHtml(data, obj){
        	 	var html = '';
			for(var i=0;i<data.length;i++){
				var temp = data[i];
				html += '<tr><td>'+moment(temp.registerEventAccTime).format('YYYY/MM/DD')+'</td><td>'+temp.registerEventName+'</td><td>'+temp.eventName+'</td><td>'+temp.registerEventContent+'</td><td>'+temp.registerEventMemo+'</td></tr>';
			}
			obj.html(html);
         }

         function receiveHtml(data, obj){
	        	 var html = '';
	        	 for(var i=0;i<data.length;i++){
	        		 var temp = data[i];
	        		 html += '<tr><td>'+moment(temp.registerEventReportTime).format('YYYY/MM/DD')+'</td><td>'+temp.registerEventName+'</td><td>'+temp.registerEventType.eventName+'</td><td>'+temp.registerEventContent+'</td><td>'+temp.registerEventMemo+'</td></tr>';
	        	 }
	        	 obj.html(html);
         }
	}
});
